function yerefresh(){
    location.reload(true);
}
function hide(){
    if($("#searchheader").css("display")=="none"){
        $("#searchheader").css("display","block");
        $("#hide").text("收起筛选")
    }else if($("#searchheader").css("display")=="block"){
        $("#searchheader").css("display","none");
        $("#hide").text("打开筛选")
    }
}

window.name="microupload";
function refresh1() {
    tableIn.reload("demo");
}
var tableIn=null;
var title1=null;
var data1=null;
var isenable=null;
    layui.use(['table','dropdown','form'], function () {
        var laydate = layui.laydate;
        console.log(data1)
        var form=layui.form
        var dropdown = layui.dropdown
        var table = layui.table;
        //监听开关按钮
        laydate.render({
            elem: '#date' //指定元素
        });
        form.on('switch(stat)', function(obj){
            var id = $(this).attr('menuId');//为了获取开关所在行的信息，需要绑定上所在行的id
            console.log('id:' + id);
            var isManager = obj.elem.checked?"1":"0";
            console.log('isManager:' + isManager);
            $.ajax({
                type:'post',
                data: {id:id,status:isManager},
                url: '/advanced/updatepermissenable',
                success:function(res){

                }
            })
        })
        table.on('tool(test)', function(obj){
            var data = obj.data;
            var layEvent = obj.event;
            var tr = obj.tr;
            if(layEvent === 'edit'){
                localStorage.setItem("selectmicroid",data.id)
                layer.open({
                    type: 2,
                    title: '编辑部门信息',
                    content: "permissionstableedit.html",
                    area: ['80%', '80%'],
                })
            } else if(layEvent === 'delete'){ //删除
                layer.confirm('真的删除行么', function(index){
                    // 向服务端发送删除指令
                    console.log(data.id);
                    $.ajax({
                        type: 'post',
                        url: '/advanced/delpermissionstable',
                        data: {id:data.id},
                        dataType: 'json',
                        success: function (res) {
                            if(res.state==200){
                                obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                                layer.close(index);
                            }
                        }
                    })

                });
            }
        });
        //第一个实例
        tableIn = table.render({
            elem: '#demo'
            , height: 800
            , id: 'demo'
            , url: '/advanced/getpermissionstable' //数据接口
            , page: true //开启分页
            , cols: [[ //表头
                {type: 'checkbox', fixed: 'left'},
                {field: 'id', title: '编号',},
                {field: 'departmentname',title: '部门名称'},
                {field: 'departmentdescription', title: '部门描述'},
                {field: 'createtime', title: '创建时间'},
                {field: 'isenable',width:100, title: '是否启用',templet:function(res){
                        let menuId=res.id;
                        if (res.isenable == 1) {
                            return "<input type='checkbox' menuId='" + menuId + "' lay-filter='stat'  lay-skin='switch' lay-text='no|yes' checked>";
                        }
                        else if(res.isenable == 0){
                            return "<input type='checkbox' menuId='" + menuId + "' lay-filter='stat'  lay-skin='switch' lay-text='no|yes'>";
                        }
                    }},
                {title: '操作', toolbar: '#barDemo'}
            ]],
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.state, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.total, //解析数据长度
                    "data": res.data //解析数据列表
                };
            },
        });
        form.on('select(isenable)', function (data) {
            console.log(data)
            isenable= data.value;
        });
        $("#selectkc").click(function(){
            var adminname=$("#adminname").val();
            var createtime=$("#date").val();
            console.log(isenable);
            var departmentname=$("#departmentname").val();
            table.reload('demo',{
                where:{
                    adminname:adminname,
                    time:createtime,
                    isenable:isenable,
                    departmentname:departmentname
                }
            })
        })
    });
$("#selectadd").click(function () {
    layer.open({
        type: 2,
        title: '添加',
        content: "addpermissionstable.html",
        area: ['80%', '80%'],
    })
})
function resett(){
    $("#addGoodsForm")[0].reset();
}
